<template>
    <div class="tab-item" @click="itemClick">
        <div v-if="!isActive"><slot name="tab-icon"></slot></div>
        <div v-else><slot name="tab-icon-active"></slot></div>
        <div :style="activeStyle"><slot name="tab-text"></slot></div>
    </div>
</template>

<script>
    export default {
        name: "TabBarItem",
        props: {
            link: String,
            activeColor: {
                type: String,
                default: 'red'
            }
        },
        data() {
            return {

            }
        },
        computed: {
          isActive() {
              return this.$route.path === this.link;
          },
          activeStyle() {
              return this.isActive ? {color: this.activeColor} : {};
          }
        },
        methods: {
            itemClick() {
                if (this.$route.path !== this.link) {
                    this.$router.push(this.link);
                }
            }
        }
    }
</script>

<style scoped>
    .tab-item {
        flex: 1;
        text-align: center;
        height: 49px; /*tabbar一般常用高度*/
        /*line-height: 49px;*/
        font-size: 14px;
    }
    .tab-item img {
        width: 24px;
        height: 24px;
        margin-top: 3px;
        vertical-align: top;
    }
</style>